package com.ctgu.j08.controller;

import com.ctgu.j08.service.DUserService;
import com.ctgu.j08.vo.DUser;
import com.ctgu.j08.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @author: Saiya Wang
 * @date: 2021/5/22 16:22
 */
@Api(value = "用户接口")
@Controller
@RequestMapping("/user")
public class DUserController {
    @Resource
    private DUserService dUserService;

//    @GetMapping("/getUserInfo")
//    @ApiOperation("获得当前用户")
//    public Result getUserInfo()
//    {
//        return ResultUtil.success();
//    }

    @PostMapping("/add")
    @ApiOperation("添加用户")
    @ResponseBody
    public Result addUser(@RequestBody DUser user){
        System.out.println("添加的用户"+user);
        return dUserService.addUser(user);
    }

    @PutMapping("/edit")
    @ApiOperation("更新用户信息")
    @ResponseBody
    public Result editUser(@RequestBody DUser dUser)
    {
        return dUserService.editUser(dUser);
    }

    @DeleteMapping("/del/{userId}")
    @ApiOperation("根据用户id删除用户")
    @ResponseBody
    public Result delUserById(@PathVariable("userId") int userId){
        System.out.println("删除Controller");
        return dUserService.delUserById(userId);
    }

    @GetMapping("/getAll")
    @ApiOperation("获取全部用户信息")
    @ResponseBody
    public Result getAllUserInfo()
    {
        return dUserService.getAllUserInfo();
    }

    @GetMapping("/search/{userName}")
    @ApiOperation("查询用户信息")
    @ResponseBody
    public Result searchUserInfo(@PathVariable("userName") String userName)
    {
        return dUserService.searchUserByName(userName);
    }
}
